package com.wan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wan.common.R;
import com.wan.dto.OrdersDto;
import com.wan.pojo.Orders;
import com.wan.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;
    /**
     * 用户下单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        orderService.submit(orders);
        return R.success("支付成功！");
    }

    /**
     * 用户查询订单
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<Page> userPage(int page, int pageSize){
        log.info("当前页：{},每页大小：{},",page,pageSize);
        Page<OrdersDto> ordersInfo = orderService.getOrdersInfo(page, pageSize);
        return R.success(ordersInfo);
    }

    /**
     * 后端订单详细信息查询
     * @param page
     * @param pageSize
     * @param number
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/page")
    public R<Page> page(int page, int pageSize, String number, String beginTime, String endTime){
        log.info("当前页：{},当前页大小：{},订单号:{},开始时间:{},结束时间:{}",page,pageSize,number,beginTime,endTime);
        Page<OrdersDto> ordersDtoPage = orderService.serverPage(page, pageSize, number, beginTime, endTime);
        return R.success(ordersDtoPage);
    }
}
